
/***************规则引擎***********************/
//arith button show
var abts=function(x){
	if($(x.id+'d').style.visibility=='inherit'){
		//按钮在关闭状态
	}else{
		$(x.id+'f').style.visibility='inherit';
		$(x.id+'v').style.visibility='hidden';
		$(x.id).onmouseout=function(){abth(this);};
	}
};
//arith button hide
var abth=function(x){
	$(x.id+'v').style.visibility='inherit';
	$(x.id+'f').style.visibility='hidden';
};
//rge cursor
var rgec=function(){
if($('.regCursor')){
		var rgec2 = new rgecTrans($('.regCursor'));
		rgec2.FadeIn();
}
};
//光标颜色切换
var rgecTrans = function(obj){
	this._obj = obj;
	this._timer = null;//定时器

	this.Speed = 500;
	this.CssColor = "color";

	this._startColor = "red";
	this._endColor = "black";
};
rgecTrans.prototype = {
  //颜色渐入
  FadeIn: function() {
	this.Stop(); 
	$(this._obj).style[this.CssColor]=this._startColor;
	this._timer = setTimeout(Bind(this, this.FadeOut), this.Speed);
  },
  //颜色渐出
  FadeOut: function() {
	this.Stop(); 
	$(this._obj).style[this.CssColor]=this._endColor;
	this._timer = setTimeout(Bind(this, this.FadeIn), this.Speed);
  },
  //停止
  Stop: function() {
	clearTimeout(this._timer);
  }
};

//设置工具栏 rge toolbar set
var rgets=function(flag){
//设置基本按钮
	for(var i=0;i<=16;i+=1){
		rgeToolbarSet(i,flag);
	}
//设置保存和退出按钮
if(flag.substr(17,1)=='1'){
	$(rgeTbPre+17).style.visibility='inherit';
	$(rgeTbPre+18).style.visibility='inherit';
	$(rgeTbPre+19).style.visibility='hidden';
	$(rgeTbPre+20).style.visibility='hidden';
}else{
	$(rgeTbPre+17).style.visibility='hidden';
	$(rgeTbPre+18).style.visibility='hidden';
	$(rgeTbPre+19).style.visibility='inherit';
	$(rgeTbPre+20).style.visibility='inherit';
}
};
//设置按钮
var rgeTbPre=".s.btntl";
var rgeToolbarSet=function(index,flag){
if(flag.substr(index,1)=='1'){
	rgeTbShow(index);
}else{
	rgeTbClose(index);
}
};
var rgeTbShow=function(index){
	if($(rgeTbPre+index+'d')){
		$(rgeTbPre+index+'v').style.visibility='inherit';
		$(rgeTbPre+index+'d').style.visibility='hidden';
	}
};
var rgeTbClose=function(index){
if($(rgeTbPre+index+'v')){
	$(rgeTbPre+index+'d').style.visibility='inherit';
	$(rgeTbPre+index+'f').style.visibility='hidden';
	$(rgeTbPre+index+'v').style.visibility='hidden';
}
}

/** 算术表达式浮动窗口位置调整 */
var ap_left,ap_top,bar_left,ref_pos;
var arithPopRePos = function(bar,barBack,navi,naviBack,cover,content,contentBack,referenceId){
	//整个窗口最左边
	  ap_left = document.body.clientWidth/2-$(navi).clientWidth/2-$(content).clientWidth/2;
	//整个窗口最上边
	  ap_top = document.body.clientHeight/2- $(navi).clientHeight/2;
	  //如果当前窗口位置有参照页面对象,按照参照页面对象位置设置当前窗口位置
	if($(referenceId)){
		ref_pos = getAbsPoint($(referenceId));
		//取参照对象的左边绝对位置和屏幕中间位置的最小值
		ap_left = Math.min(ap_left,ref_pos.x);
		//取参数对象的上边绝对位置和屏幕中间位置的最小值
		ap_top = Math.min(ap_top,ref_pos.y);
	}
	//导航栏及其遮罩
	$(navi).style.top = ap_top;
	$(navi).style.left = ap_left;
	$(cover).style.top = ap_top;
	$(cover).style.left = ap_left;
	$(naviBack).style.top = ap_top;
	$(naviBack).style.left = ap_left;
	//工具栏左边为窗口左边+导航栏宽度
	bar_left = ap_left+$(navi).offsetWidth;
	//工具栏
	$(bar).style.top = ap_top;
	$(bar).style.left = bar_left;
	$(barBack).style.top = ap_top;
	$(barBack).style.left = bar_left;
	//内容区域
	$(content).style.top = ap_top+$(bar).offsetHeight;
	$(content).style.left = bar_left;
	$(contentBack).style.top = ap_top+$(bar).offsetHeight;
	$(contentBack).style.left = bar_left;
	$(content).style.height = $(navi).clientHeight - $(bar).clientHeight+17;
	$(contentBack).style.height = $(navi).clientHeight - $(bar).clientHeight+17;
}


/**字段树的展开与隐藏*/
var fieldClick = function(id){
	if($(id+"f").style.display == "none"){
		$(id+"f").style.display = "block";
	}else{
		$(id+"f").style.display = "none";
	}
};
/**根据传来的算术表达式值类型,来隐藏非该类型的字段*/
var fieldHidden = function(dataType){
	var childs = $(fieldShow).getElementsByTagName("DIV");
	for (i = 0; i < childs.length; i+=1) {
		if (childs[i]!== null 
		         && childs[i].id !== "undefind" 
		         && childs[i].id !== "" 
		         && childs[i].id.split(",").length > 1
		         && childs[i].id.split(",")[0]=="field") {
			if(childs[i].id.split(",")[1]==dataType){
				$(childs[i].id).style.display="block";
			}else{
				$(childs[i].id).style.display="none";
			}
		}
	}
}
